<!-- 
 -- AddSampleLib.php
 -- v0.01
 -- 3/7/11
 --
 -- The functions in this file moderates database functions which
 -- involve adding samples.
 -->

<?php
	/**
	 * The function inserts a new sample into the database table named
	 * 'sample' given the parameters below:
	 * @param unknown_type $casl_num
	 * @param unknown_type $sample_num
	 * @param unknown_type $sampling_date
	 * @param unknown_type $submitted_by
	 * @param unknown_type $sample_type
	 * @param unknown_type $received_by
	 * @param unknown_type $remarks
	 * @param unknown_type $database
	 * @param unknown_type $host
	 * @param unknown_type $login
	 * @param unknown_type $loginpassword
	 */
	function InsertNewSample($casl_num, $sample_num, $sampling_date,
			$submitted_by, $sample_type, $received_by, $remarks,
			$database, $host, $login, $loginpassword){ 
		//Create connection.
		$connect = mysql_connect($host, $login, $loginpassword);
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		mysql_select_db($database, $connect);
		
		//Set-up and execute query.
		$addSampleQuery = "INSERT INTO sample VALUES ('$sample_num',
				'$casl_num', '$sampling_date', '$submitted_by', 
				'$sample_type', '$received_by', '$remarks')";
		$addSample = mysql_query($addSampleQuery);
		echo $addSample."</br>";
		
		//Check data generated.
		if ($addSample == TRUE) {	
			echo "SUCCESSFUL!";
		} else {
			echo "ERROR!";
		}
		echo $sample_num;
		
		//Close connection.
		mysql_close($connect);
		if ($addSample == TRUE) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
	
	/**
	 * The function lets the caller PHP file display all analysis types.
	 * @param unknown_type $database
	 * @param unknown_type $host
	 * @param unknown_type $login
	 * @param unknown_type $loginpassword
	 */
	function DisplayAllAnalysisTypes($database, $host, $login, $loginpassword){
		//Create connection.
		$connect = mysql_connect("localhost","createanalysis","createanalysis");
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		mysql_select_db($database, $connect);
		
		//Set-up and exectute query.
		$result = mysql_query("SELECT DISTINCT SAMPLE_TYPE FROM cost_analysis");
		$listall= NULL;
		$inti=0;
		
		//Print data generated.
		while($row = mysql_fetch_array($result) ){
			echo '<option value="'.$row["SAMPLE_TYPE"].'">'.$row["SAMPLE_TYPE"].
					'</option>';
		}
		
		//Close connection.
		mysql_close($connect);
	}

	/**
	 * The function lets the caller PHP file display all analysis subtypes.
	 * @param unknown_type $database
	 * @param unknown_type $host
	 * @param unknown_type $login
	 * @param unknown_type $loginpassword
	 * @param unknown_type $analysis_type
	 */
	function DisplayAllAnalysisSubtypes($database, $host, $login, $loginpassword,
			$analysis_type){
		//Createconnection.
		$connect = mysql_connect("localhost","createanalysis","createanalysis");
		if (!$connect) {
			die('Could not connect: ' . mysql_error());
		}
		mysql_select_db($database, $connect);
		
		//Set-up and execute query.
		$result = mysql_query("SELECT ANALYSIS_TYPE FROM cost_analysis WHERE 
				SAMPLE_TYPE='$analysis_type'");
		$listall= NULL;
		$inti=0;
		
		//Print data gathered.
		echo "<div style='font:13.3px sans-serif;width:12em;border-left:1px 
				solid #808080;border-top:1px solid #808080;
				border-bottom:1px solid #fff; border-right:1px solid #fff;'>
				<div style='background:#fff; overflow:auto;height:7.1em;
				border-left:1px solid #404040;border-top:1px solid #404040;
				border-bottom:1px solid #d4d0c8;
				border-right:1px solid #d4d0c8;'>";
		while($row = mysql_fetch_array($result)){
			echo "<label for='cb$inti' style='padding-right:3px;
					display:block;'><input name='checkbox[]' value='$inti'
					type='checkbox' id='cb$inti'
					onclick='highlight_div(this);'>
					$row[ANALYSIS_TYPE]</label>";
			$inti++;
		}
		echo "</div></div>";
		
		//Close connection.
		mysql_close($connect);
	}
?>